package org.tloss.cluster;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@SuppressWarnings("serial")
public class Cluster_serverServlet extends HttpServlet {

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		PrintWriter printWriter =  new PrintWriter(resp.getOutputStream());
		Enumeration enumeration = req.getHeaderNames();
		while (enumeration.hasMoreElements()) {
			String name = (String) enumeration.nextElement();
			printWriter
					.println("" + name + "=" + req.getHeader(name) + "<br/>");
		}
		HttpSession session = req.getSession(true);
		if (session != null) {
			printWriter.println("sessionid=" + session.getId() + "<br/>");
			if(session.getAttribute("ABC")==null){
				session.setAttribute("ABC",new TestSession());
				printWriter.println("NEW ABC:"+ session.getAttribute("ABC")+"<br/>");
			}else{
				printWriter.println("ABC=" + session.getAttribute("ABC")+ "<br/>");
			}
		}
		printWriter.flush();
	}

}
